package cn.nosql.myservice;

import cn.nosql.service.IMyLexical;

public class MyLexicalService {
    private IMyLexical noSql;

    public IMyLexical getNoSql() {
        return noSql;
    }

    private static class InstanceHolder {

        public static MyLexicalService instance;

        static {
            try {
                instance = new MyLexicalService();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 获取单例模式
     * */
    public static MyLexicalService getInstance() {
        return MyLexicalService.InstanceHolder.instance;
    }

    /**
     * 构造函数设置为私有，只能通过 getInstance() 方法获取
     * */
    private MyLexicalService() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        Class<?> cls = Class.forName("org.dawnsql.tools.MyLexical");
        noSql = (IMyLexical) cls.newInstance();
    }
}
